package com.yaoli.meituan;

import java.util.Collections;
import java.util.Scanner;

/**
 * Created by will on 2017/6/13.
 */
public class Test01 {


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int len1 = in.nextInt();
        int array1 [] = new int[len1];
        for(int i = 0 ; i < len1 ; i++){
            array1[i] = in.nextInt();
        }

        int len2 = in.nextInt();
        int array2 [] = new int[len2];
        for(int i = 0 ; i < len2 ; i++){
            array2[i] = in.nextInt();
        }
//        int array1 [] = {1,2};
//        int array2 [] = {3,1,2,4};

        int min = Integer.MAX_VALUE;

        for(int i = 0 ; i < array2.length - array1.length + 1; i++){
            int total = 0;
            for(int j = 0 ; j < array1.length ; j++){
                total = total + (array1[j] - array2[i + j])*(array1[j] - array2[i + j]);
            }
            min = Math.min(min,total);
        }



        System.out.println(min);

    }
}
